package com.manor.common.utils

import android.view.View
import android.widget.EditText
import android.widget.TextView
import java.math.BigDecimal

/**
 *


 * @date  2020/6/28  17:25
 * @version 1.0
 */
fun EditText.str(): String {
    return if (this.text.isNullOrEmpty())
        ""
    else
        this.text.toString().trim()
}

fun TextView.str(): String {
    return if (this.text.isNullOrEmpty())
        ""
    else
        this.text.toString().trim()
}

fun EditText.len(): Int {
    return if (this.text.isNullOrEmpty())
        0
    else
        this.str().length
}

fun TextView.len(): Int {
    return if (this.text.isNullOrEmpty())
        0
    else
        this.str().length
}

fun EditText.strNotNull(): Boolean {
    return "null" != this.str() && this.str().trim { it <= ' ' }.isNotEmpty()
}

fun TextView.strNotNull(): Boolean {
    return "null" != this.str() && this.str().trim { it <= ' ' }.isNotEmpty()
}



fun EditText.strIsNull(): Boolean {
    return this.str().isEmpty()
}

fun TextView.strIsNull(): Boolean {
    return this.str().isEmpty()
}

fun String?.notNull(): Boolean {
    return  this!=null && "" != this && this.trim { it <= ' ' }.isNotEmpty()
}



 fun View.setVisible(isVisible: Boolean) {
    this.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
}

 fun View.setGone(isGone: Boolean) {
     this.visibility = if (isGone) View.GONE else View.VISIBLE
}

fun BigDecimal.scaleDown(scale :Int) :BigDecimal{
    return this.setScale(scale, BigDecimal.ROUND_DOWN)
}

fun BigDecimal.scaleUp(scale :Int) :BigDecimal{
    return this.setScale(scale, BigDecimal.ROUND_UP)
}

fun BigDecimal.divideDown(bigDecimal: BigDecimal, scale: Int): BigDecimal{
    return this.divide(bigDecimal, scale, BigDecimal.ROUND_DOWN )
}


